package com.itheima.mall.web.oms;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mall.commons.page.PageResult;
import com.itheima.mall.commons.result.Result;
import com.itheima.mall.dubbo.api.oms.OrderReturnApplyService;
import com.itheima.mall.entity.domain.oms.OrderReturnApply;
import com.itheima.mall.entity.dto.oms.OmsOrderReturnApplyResult;
import com.itheima.mall.entity.dto.oms.OmsRetunDto;
import com.itheima.mall.entity.dto.oms.OmsReturnApplyQueryParam;
import com.itheima.mall.entity.dto.oms.OmsUpdateStatusParam;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单退货申请 前端控制器
 * </p>
 *
 * @author qinglang
 * @since 2022-07-05
 */
@RestController
@RequestMapping("returnApply")
@CrossOrigin(origins = "*")
public class OrderReturnApplyController {

    @DubboReference
    private OrderReturnApplyService returnApplyService;

    /**
     * 分页查询退货申请
     * @return
     */
    @GetMapping("list")
    public Result list(OmsReturnApplyQueryParam param){

        Page<OrderReturnApply> orderReturnApplyPage = new Page<>(param.getPageNum(),param.getPageSize());
        Page<OrderReturnApply> page = returnApplyService.page(orderReturnApplyPage);
        return Result.success(PageResult.init(page.getRecords(),page.getCurrent(),page.getSize(),page.getTotal()));
    }

    /**
     * 批量删除退货申请
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public Result delete(@RequestParam List<Integer>ids){
//        LambdaQueryWrapper<Object> wrapper = new LambdaQueryWrapper<>();
        returnApplyService.removeByIds(ids);
        return Result.success();
    }

    /**
     * 修改退货申请状态
     * @param param
     * @param id
     * @return
     */
    @PostMapping("update/status/{id}")
    public Result updateStatus(@RequestBody OrderReturnApply param, @PathVariable Integer id) {
        param.setId(id);
       returnApplyService.updateById(param);
        return Result.success();
    }

    /**
     * 获取退货申请详情
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result getItem(@PathVariable Integer id){
        OrderReturnApply byId = returnApplyService.getById(id);
        return Result.success(byId);
    }

}

